<%--
 *  File:    ProdEditMain.jsp
 *  @Author: Langerwang
 *  Date:    2001/01/14
 *  @Modifier: Jamesli
 *  Date:    2010/07/06
 *
 *  Copyright (C) 2000 - 2010 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>




<%
  //init param
  Category cat = Category.getInstance("jsp.ProdEditMain");
  String privilegeCode = "10203,L203";
  String strModuleName = "PCM";
  String contextPath = request.getContextPath();
%>
<%@ include file="/inc/CommonHeader.inc" %>
<%
	String prodid = (String)request.getParameter("prodid");
  String strIsNew=prodid != null?"N":"Y";
  //System.out.println((String)request.getParameter("isnew"));
  //Enumeration en = request.getParameterNames();
  //while(en.hasMoreElements())
  // System.out.println("a "+en.nextElement());
  if(strIsNew==null)
    strIsNew="";
%>
<%
  HashMap userInfo = (HashMap)session.getAttribute("userinfo");

%>

<html>
<head>
<title>ProdEditMain</title>
<PageFlow:CheckPageFlow pageName="prodeditmain"/>
<%@ include file="/inc/InitEdit.inc" %>
<%
  Integer nOldProdLineID = null;
  if ((HashMap)pageContext.getAttribute("productinfo") != null)
  {
    nOldProdLineID = (Integer)(((HashMap)pageContext.getAttribute("productinfo")).get("prodlineid"));
  }  
%>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath %>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath %>/js/FuncLib.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/ScriptLib.js"></script>
<iframe name="reloadHandler" style="display:none" ></iframe>
<script language="JavaScript">
function checkboxvalue()
{
  if(prodeditmainform.islot.checked)
    prodeditmainform.islotcontrol.value="Y";
  else
    prodeditmainform.islotcontrol.value="N";

  if(prodeditmainform.isserial.checked)
    prodeditmainform.isserialnumcontrol.value="Y";
  else
    prodeditmainform.isserialnumcontrol.value="N";

 if(prodeditmainform.isexpire.checked)
    prodeditmainform.isexpirationcontrol.value="Y";
  else
    prodeditmainform.isexpirationcontrol.value="N";

}
function checkProdEditMain(form)
{
  if(!isNumberic(form.unitprice.value))
  {
    alert('<%=message.getMessageDesc("VALUE_MUST_BE_NUMBER",label.getLabelName("L_Price",false)) %>');
    return false;
  }
  return true;
}

function page_done()
{
	checkprice();
	if(!checkNull(document.prodeditmainform)) return;
	if(!checkForm(document.prodeditmainform)) return;
	checkNumber(prodeditmainform);

   MLCSTransform(prodeditmainform);

   emptyToNull(prodeditmainform);

  prodeditmainform.numrows.value = Number(<%= ConstantProp.multiLangNumber %>)*(0+1);

  <%if(strIsNew.equals("Y")){%>
  document.prodeditmainform.itemcode.value=document.prodeditmainform.prodcode.value
  document.prodeditmainform.listprice.value=document.prodeditmainform.unitprice.value
  <%}%>
  
  document.prodeditmainform.actionname.value = "done";
  document.prodeditmainform.target="_self";
  //isRunning = true;
  //document.prodeditmainform.submit();
  __submitData('cformid',true);
}


var popwindow;
function page_mulilang(name,label,num,need)
{
  if(popwindow!=null)
    popwindow.close();
  var strurl="<%=contextPath %>/common/Lang.jsp?<%= OvalTools.randomURL() %>&form=prodeditmainform&module=PCM&mlctype="+label+"&nativelanguage="+need+"&schema=ovproductlang&entityid=<custom:write name="productinfo" property="prodid"/>&entitytype="+name+"&contentid=productlangid&colindex="+num;
  var strStatus= "height=250, width=250,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no";
  popwindow=window.open(strurl, "newwindow",strStatus);
}
function page_back()
{
  parent.up.page_goback();
}

  function page_reload()
{
  var itemgroupcode=document.prodeditmainform.itemgroupcode.value;
  var orgid=document.prodeditmainform.orgid.value;
  
  document.prodeditmainform.actionname.value = "reload"; 
  document.prodeditmainform.target = "_self";
  isRunning = true;
  document.prodeditmainform.submit();
}
function page_itemgrouppop()
{
    var status="height=380, width=600,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no";
    var url="../ogm/ItemGroupMapPop.jsp?<%= OvalTools.randomURL() %>&isall=Y";
    if(popwindow!=null)
      popwindow.close();
   popwindow=window.open(url, "newwindow", status);
}
function page_setItemGroup(itemgroupid,itemgroupname,itemgroupcode)
 {
    document.prodeditmainform.itemgroupid.value=itemgroupid;
    document.prodeditmainform.itemgroupname.value=itemgroupname;
    document.prodeditmainform.itemgroupcode.value=itemgroupcode;
 }

 function page_setItem()
{
    prodeditmainform.itemgroupid.value='';
    prodeditmainform.itemgroupname.value='';
    prodeditmainform.schema.value="v_itemgroupsummary";
    prodeditmainform.qlname.value="selectbycode";
    page_handleRequest('<%=contextPath%>',prodeditmainform);
}
function page_handleResponse()
{
    if(getResponseData("categoryid")!=null&&getResponseData("categoryid")!="")
    {
        prodeditmainform.categoryid.value = getResponseData("categoryid");
        prodeditmainform.categorycode.value = getResponseData("categorycode");
        prodeditmainform.categoryname.value = getResponseData("categoryname");
    }
    if(getResponseData("itemgroupid")!=null&&getResponseData("itemgroupid")!="")
    {
    prodeditmainform.itemgroupid.value = getResponseData("itemgroupid");
    prodeditmainform.itemgroupcode.value = getResponseData("itemgroupcode");
    prodeditmainform.itemgroupname.value = getResponseData("itemgroupname");
    }
	if(getResponseData("nextprodid")!=null&&getResponseData("nextprodid")!="")
	{
           prodeditmainform.nextprodname.value = getResponseData('prodname');
         prodeditmainform.nextprodid.value = getResponseData('prodid');
         if (prodeditmainform.nextprodid.value != "")
           prodeditmainform.nextprodcode.value = getResponseData('prodcode');
     }
}
function page_setcategory(categorycode)
{
     prodeditmainform.categoryname.value ="";
     prodeditmainform.categoryid.value ="";

     if(categorycode!=null&&categorycode!="")   prodeditmainform.categorycode.value =categorycode;

     if(prodeditmainform.categorycode.value=="")
     {
       prodeditmainform.categoryname.value ="";
       return;
     }

     else
     {
       prodeditmainform.schema.value="ovcategory";
       prodeditmainform.qlname.value="selectchildbycode";
       page_handleRequest('<%=contextPath%>',prodeditmainform);
     }
}
function popproduct()
{
  window.open("../kdm/ProductSelect.jsp?<%= OvalTools.randomURL() %>&selopt=sub&selfprodid="+prodeditmainform.prodid.value, "newwindow","height=400, width=600,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");

}

function reloadnextprod()
{
  if (isEmpty(prodeditmainform.nextprodcode.value)){
    prodeditmainform.nextprodid.value=" ";
    prodeditmainform.nextprodname.value="";
    prodeditmainform.nextprodcode.value="";
      return;
    }

    var  datahandler = new  DataHandler();
    datahandler.add_params("searchname","prodcode") ;
    datahandler.add_params("searchvalue" , eval("document.prodeditmainform.nextprodcode").value) ;
    datahandler.add_params("selopt","sub") ;
    datahandler.add_params("selfprodid",eval("document.prodeditmainform.prodid").value) ;
    datahandler.getResultFromHashMap("productsum" ,"prodcode" ,"document.prodeditmainform.nextprodcode");
    datahandler.getResultFromHashMap("productsum" ,"prodname" ,"document.prodeditmainform.nextprodname");
    datahandler.getResultFromHashMap("productsum" ,"prodid" ,"document.prodeditmainform.nextprodid");
    datahandler.add_job("getproductselect") ;
    datahandler.runDataHandler ();
}

 function page_setproduct(id,umcode,prodcode,prodname)
 {
     document.prodeditmainform.nextprodcode.value = prodcode;
     document.prodeditmainform.nextprodid.value = id;
     document.prodeditmainform.nextprodname.value = prodname;
     var remote = window.open("","newwindow");
     if (remote != null)
       remote.close();
 }
 
function checkprice(){
	var unitprice = document.prodeditmainform.unitprice.value;
	if (Trim(unitprice) != ''){
		document.prodeditmainform.unitprice.command='positive';
	}else{
		document.prodeditmainform.unitprice.command='';
	}
}
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table border=0 cellpadding=0 cellspacing=0 width="100%">
  <tr>
    <td valign=top>
      <table border=0 cellpadding=1 cellspacing=0 width="100%">
       <tbody>
       <form id="cformid" name="prodeditmainform" method="post" action="<%=contextPath %>/Dispatcher">
      <input type="hidden" name="pagename" value="prodeditmain">
      <input type="hidden" name="actionname">
      <input type="hidden" name="schema" value="">
      <input type="hidden" name="qlname" value="">
       <custom:hidden name="productinfo" property="prodid"/>
       <%
        String strorgid="";
        if(request.getParameter("orgid")!=null)
        {
            strorgid=(String)request.getParameter("orgid");
        }
        String strownerid="-1";
        if(request.getParameter("ownerid")!=null)
        {
            strownerid=(String)request.getParameter("ownerid");
        }
       %>
       <custom:hidden name="productinfo" property="orgid" value="<%=strorgid %>"/>
       <custom:hidden name="productinfo" property="languagecode" value="<%= strLanguageCode %>"/>
       <input type="hidden" name="datelastupdated" value="<%=JspHelper.filterNull( new java.sql.Date(new java.util.Date().getTime()) )%>"/>
       <custom:hidden name="productinfo" property="revision"/>
       <custom:hidden name="productinfo" property="productlangid"/>
      <input type="hidden" name="numrows" value="2">
      <input type="hidden" name="forremvoe" value=" ">
      <input type="hidden" name="copyprodlinedesc" value="N">
      <custom:hidden property="ownerid" value="<%=strownerid%>"/>
      <custom:hidden property="categoryorgid"/>
      <custom:hidden property="categoryid" changedName="categoryidforgoto"/>
      <custom:hidden property="selectopt"/>
      <custom:hidden property="orderbycolumn"/>
      <custom:hidden property="orderbytype"/>
      <custom:hidden property="jumppage"/>
      <custom:hidden property="searchname"/>
      <custom:hidden property="searchvalue"/>

      <%if(strIsNew.equals("Y")){
      System.out.println("here new");%>
      <input type="hidden" name="isnew" value="Y"/>
	   <input type="hidden" name="sourceorgid" value="<%=JspHelper.filterNull( strorgid)%>">
	   <custom:hidden name="productinfo" property="prodcode"  changedName="itemcode"/>
	   <custom:hidden name="productinfo" property="unitprice"  changedName="listprice"/>
	   <input type="hidden" name="isbom" value="N">
	   <input type="hidden" name="ispublic" value="N">
      <%}%>
        <tr>
          <td bgcolor=#000000 style="PADDING-BOTTOM: 1px; PADDING-LEFT: 1px; PADDING-RIGHT: 1px; PADDING-TOP: 0px">
            <table bgcolor=#000000 border=0 cellpadding=0 cellspacing=0 width="100%">
              <tr>
                <td  bgcolor=#ffffff style="PADDING-BOTTOM: 3px; PADDING-LEFT: 3px; PADDING-RIGHT: 3px; PADDING-TOP: 3px">
                  <div id=div1 style="HEIGHT: 300px; OVERFLOW: auto">

        <table border="1" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" align="center" width="100%" cellpadding="0">
          <tr>
            <td colspan="4" class="td_right"><a onclick="page_done();"><custom:button type="2" label="L_Save" imgsrc="save_btn.gif" border="0"/></a></td>
          </tr>
          <tr>
            <td colspan="4" class="deepblue-left"> <img src="<%=contextPath %>/images/<%= strLanguageCode %>/quote.gif">
              <%= label.getLabelName("L_BasicInfo") + label.getLabelName("L_Colon") %> </td>
          </tr>
          <%
            String strNeedClass="td-text";
            String strReadOnly="readonly";
            boolean strDisabled = true;
            String strIsNull="Y";
            if(strIsNew.equals("Y"))
            {
              strNeedClass="need";
              strReadOnly="";
              strIsNull="N";
              if(null == pageContext.getAttribute("categoryid"))strDisabled = false;
            }
          %>
          <tr>
            <td class="<%=JspHelper.filterNull(strNeedClass)%>" width="120"><%= label.getLabelName("L_ProdCode") + label.getLabelName("L_Colon") %></td>
            <td  >
              <%if(isView){ %>
              <custom:write name="productinfo" property="prodcode"/>
              <%}else {%>
              <input type="text" isnull="<%=JspHelper.filterNull(strIsNull)%>" value="<custom:write name="productinfo" property="prodcode"/>" <%=JspHelper.filterNull(strReadOnly)%> label="<%=message.getMessageDesc("VALUE_NOT_NULL",label.getLabelName("L_ProdCode",false))%>" size="20"  name="prodcode"/>
              <%} %>
            </td>
            <td class="need" width="106" ><%= label.getLabelName("L_ProdType") + label.getLabelName("L_Colon") %></td>  
            <td><custom:select  optionsName="allcategories" optionValueKey="categoryid" optionInnerTextKey="categoryname" name="productinfo" property="categoryid" changedName="categoryselect" defaultValueCost="" defaultValue="-----" disabled="<%= strDisabled%>" onchange="javascript:prodeditmainform.categoryid.value = this.options[this.selectedIndex].value;"/></td>
            <custom:hidden property="categoryid" name="productinfo"/>
          </tr>
          <tr>
            <td class="need"><%= label.getLabelName("L_ProductName") + label.getLabelName("L_Colon") %></td>
            <td>
              <custom:text name="productinfo" property="prodname" size="20" command="notnull" module="PCM" label="L_ProductName" needMLC="true" isFirstMLC="true" multiLangType="prdn" entityId="prodid" contentId="productlangid" colIndex="0"/>
            </td>
            <td class="need"><%= label.getLabelName("L_Spec") + label.getLabelName("L_Colon") %></td>
            <td>
              <custom:text name="productinfo" property="spec" command="notnull" label="L_Spec"/>
            </td>
          </tr>
          <tr>
            <td class="td-text" ><%= label.getLabelName("L_Addreviate") + label.getLabelName("L_Colon") %></td>
            <td >
              <custom:text name="productinfo" property="shortname" size="20"/>
            </td>
            <td class="need"><%= label.getLabelName("L_SmallPackage") + label.getLabelName("L_Colon") %></td>
            <td  >
              <custom:text name="productinfo" property="smallpacknum" size="20"  module="PCM" label="L_SmallPackage" needMLC="true" command="notnull,notnegative" dataType="integer"/>
            </td>
          </tr>
          <tr>
            <td class="need"><%= label.getLabelName("L_Brand") + label.getLabelName("L_Colon") %></td>
            <td >
               <custom:select  optionsName="allbrands" optionValueKey="brandcode" optionInnerTextKey="brandname" name="productinfo" property="brandcode" defaultValueCost="" defaultValue="-----" command="notnull" module="PCM" label="L_Brand"/>
            </td>
              <td class="need"><%= label.getLabelName("L_status") + label.getLabelName("L_Colon") %></td>
            <td >
               <custom:selectdic name="productinfo" dictType="Status" property="status"  defaultValueCost="" defaultValue="---"  valueCriteria="41,28" label="L_status" command="notnull"/>
            </td>
          </tr>
          
          <tr>
            <td class="need"><%= label.getLabelName("L_UOM") + label.getLabelName("L_Colon") %></td>
            <td >
        	    <%
        	    Integer umused=(Integer)pageContext.getAttribute("umused");
        	    if(umused == null){
        	    %>
                <custom:select optionsName="allumcode" optionValueKey="umcode" defaultValueCost="" defaultValue="-----"  optionInnerTextKey="umname" name="productinfo" property="umcode" command="notnull" label="L_UOM"/>
          		<%}else{%>
          		<select disabled name=umcode>
          		<option value='<oval:write name="productinfo" property="umcode"/>' selected><oval:write name="productinfo" property="umname"/></option>
          		<%}%>
            </td>
            <td class="td-text" width="106"><%= label.getLabelName("L_SupplyPrice") + label.getLabelName("L_Colon") %></td>
            <td >
			        <custom:text property="unitprice" name="productinfo" size="20" label="L_SupplyPrice" dataType="number" command="notnegative"/>
            </td>
          </tr>
          <tr>
            <td class="need"><%= label.getLabelName("L_Spec1") + label.getLabelName("L_Colon") %></td>
            <td>
               <custom:selectdic name="productinfo" dictType="Spec" property="formulation" defaultValue="-----" label="L_Spec1" command="notnull"/>
            </td>
             <td class="need"><%= label.getLabelName("L_YesOrNoPrescription") + label.getLabelName("L_Colon") %></td>
            <td>
               <custom:selectdic name="productinfo" dictType="YesOrNo" property="nototc" valueCriteria="1,2" defaultValueCost="" defaultValue="-----" label="L_YesOrNoPrescription" command="notnull"/>
            </td>
          </tr>
            <tr>
            <td class="need"><%= label.getLabelName("L_Factor") + label.getLabelName("L_Colon") %></td>
            <td>
               <custom:text property="factor" name="productinfo" ></custom:text>
            </td>
             <td class="td-text"><%= label.getLabelName("L_Other") + label.getLabelName("L_Code") + label.getLabelName("L_Colon") %></td>
            <td>
               <custom:text property="othercode" name="productinfo" ></custom:text>
            </td>
          </tr>
        </table>
       </div>
      </td>
    </tr>
   </table>
  </td>
 </tr>
</form>
 </tbody>
</table>
</td>
</table>
<script>
//checkNumber(prodeditmainform);
</script>
</body>
</html>